<@t.header>
<link rel="stylesheet" href="${request.contextPath}/app/contract/css/contract-create.css">
</@t.header> <@t.body> <#if (invalid?? && invalid) || (notfound?? && notfound)>
<div class="alert alert-danger" role="alert">
	<strong>警告！</strong>
	无效的合同信息！
</div>
<#elseif cannotedit?? && cannotedit>
<div class="alert alert-danger" role="alert">
	<strong>警告！</strong>
	您无法编辑该信息！
</div>
<#elseif errortype?? && errortype>
<div class="alert alert-danger" role="alert">
	<strong>警告！</strong>
	合同类型无效
	<a href="${request.contextPath}/contract/view/${data.id}">返回</a>
</div>
<#else>
<div class="navbar navbar-default navbar-fixed-top padding-0 margin-0">
	<div class="container-fluid">
		<div class="navbar-header">
			<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#suredy-form-navbar">
				<span class="icon-bar"></span>
				<span class="icon-bar"></span>
				<span class="icon-bar"></span>
			</button>
			<span class="navbar-brand">
				<i class="icon-paste icon-large"></i>
				编辑${data.type.value}
			</span>
		</div>
		<div class="collapse navbar-collapse" id="suredy-form-navbar">
			<ul class="nav navbar-nav suredy-form-bar">
				<li>
					<a href="javascript:void(0);" class="submit-contract-info">
						<i class="icon-ok icon-large"></i>
						修改
					</a>
				</li>
				<li>
					<a href="javascript:void(0);" class="reset-form-info">
						<i class="icon-undo icon-large"></i>
						重置表单
					</a>
				</li>
			</ul>
		</div>
	</div>
</div>

<div class="container" style="padding-top: 60px;">
	<form class="form-create-contract" action="${request.contextPath}/dm/contract-edit" method="post">
		<input type="hidden" name="id" value="${data.id}" />
		<div class="panel panel-primary">
			<div class="panel-heading">
				<h3 class="panel-title">基本信息</h3>
			</div>
			<div class="panel-body" style="padding-bottom: 0;">
				<div class="row">
					<div class="col-md-12">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span>
										合同名称
									</div>
								</div>
								<input type="text" class="form-control not-empty" name="name" value="${data.name}" placeholder="最多100个汉字">
							</div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span>
										建设单位
									</div>
								</div>
								<select class="form-control not-empty" name="companyA">
									<#if 'A_CONTRACT'==data.type && company??> <#list company as c>
									<option value="${c}" ${((data.companyA==c)?string('selected',''))!''}>${c}</option>
									</#list> <#else> <#if biddingers??> <#list biddingers as bs>
									<option value="${bs.company}" ${((data.companyA==bs.company)?string('selected',''))!''}>${bs.company}</option>
									</#list> </#if> </#if>
								</select>
							</div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span>
										承建单位
									</div>
								</div>
								<#if 'B_CONTRACT'==data.type && company??>
								<select class="form-control not-empty" name="companyB">
									<#list company as c>
									<option value="${c}">${c}</option>
									</#list>
								</select>
								<#else>
								<input type="text" class="form-control not-empty" name="companyB" value="${data.companyB}">
								</#if>
							</div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span>
										合同编号
									</div>
								</div>
								<input type="text" class="form-control not-empty" name="no" value="${data.no}" placeholder="最多50个字符">
							</div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span>
										<#if data.moneyType=='TOTAL'>
										合同总价
										<#elseif data.moneyType=='SINGLE'>
										合同单价
										<#elseif data.moneyType=='DROP_POINT'>
										合同降点
										</#if>
									</div>
								</div>
								<#if data.moneyType=='TOTAL'>
								<input type="text" class="form-control not-empty number" name="price" value="${data.price}" placeholder="只能是数字">
								<div class="input-group-addon">元</div>
								<#else>
								<textarea rows="1" class="form-control not-empty" name="priceDes" style="resize:none;" onfocus="$(this).attr('rows', 5);" onblur="$(this).attr('rows', 1);" placeholder="最多500个汉字">${data.priceDes}</textarea>
								</#if>
							</div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span>
										签订日期
									</div>
								</div>
								<input type="text" class="form-control not-empty datetimepicker" name="signDate" data-foot="false" data-format="yyyy-MM-dd" value="${(data.signDate?string('yyyy-MM-dd'))!''}" readonly="readonly">
							</div>
						</div>
					</div>
					<div class="col-md-6">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span>
										办结日期
									</div>
								</div>
								<input type="text" class="form-control not-empty datetimepicker" name="bjTime" data-foot="false" data-format="yyyy-MM-dd" value="${(data.bjTime?string('yyyy-MM-dd'))!''}" readonly="readonly" placeholder="请选择日期">
							</div>
						</div>
					</div>
					<div class="col-md-12">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span>
										合同工期
										<small class="text-danger contract-days-helper" style="font-weight: bold; cursor: pointer;">？</small>
									</div>
								</div>
								<input type="text" class="form-control datetimepicker" name="contractStart" value="${(data.contractStart)!''}" data-foot="false" data-format="yyyy-MM-dd" readonly="readonly" placeholder="开工日期">
								<div class="input-group-addon" style="border-left: none; border-right: none;">至</div>
								<input type="text" class="form-control datetimepicker" name="contractEnd" value="${(data.contractEnd)!''}" data-foot="false" data-format="yyyy-MM-dd" readonly="readonly" placeholder="竣工日期">
								<div class="input-group-addon" style="border-left: none; border-right: none;">工期天数</div>
								<input type="text" class="form-control number" name="contractDays" value="${data.contractDays}" placeholder="工期天数">
								<div class="input-group-addon" style="border-left: none;">天</div>
							</div>
						</div>
					</div>
					<div class="col-md-12">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span>
										结算方式
									</div>
								</div>
								<textarea rows="3" class="form-control not-empty" name="jiesuanWay" placeholder="最多500个汉字">${data.jiesuanWay}</textarea>
							</div>
						</div>
					</div>
					<div class="col-md-12">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span>
										付款方式
									</div>
								</div>
								<textarea rows="3" class="form-control not-empty" name="fukuanWay" placeholder="最多500个汉字">${data.fukuanWay}</textarea>
							</div>
						</div>
					</div>
					<div class="col-md-12">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span>
										工程内容
									</div>
								</div>
								<textarea rows="3" class="form-control not-empty" name="mainContent" placeholder="最多1000个汉字。">${data.mainContent}</textarea>
							</div>
						</div>
					</div>
					<div class="col-md-12">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">
										<span class="not-null-star">*</span>
										承包范围
									</div>
								</div>
								<textarea rows="3" class="form-control not-empty" name="chengbaoFanwei" placeholder="最多1000个汉字。">${data.chengbaoFanwei}</textarea>
							</div>
						</div>
					</div>
					<div class="col-md-12">
						<div class="form-group">
							<div class="input-group">
								<div class="input-group-addon">
									<div class="form-item-title">备注</div>
								</div>
								<textarea rows="3" class="form-control" name="remark" placeholder="最多1000个汉字">${data.remark}</textarea>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>

		<hr style="margin-top: 5px;">
	</form>
</div>
</#if> </@t.body> <@t.foot>
<script src="${request.contextPath}/core/js/jquery.form.js"></script>
<script src="${request.contextPath}/js/suredy-modal.js"></script>
<script src="${request.contextPath}/js/suredy-datetimepicker.js"></script>
<script src="${request.contextPath}/app/js/form-checker.js"></script>

<script type="text/javascript">
	$(function() {
		// 初始化日期控件
		$.suredy.datetimepicker.init();

		// 提交合同信息
		$('a.submit-contract-info').on('click', function() {
			var form = $('form.form-create-contract');

			// 校验表单
			if (!$.suredy.formChecker(form)) {
				return false;
			}

			var cStart = $('[name="contractStart"]').val();
			var cEnd = $('[name="contractEnd"]').val();
			var cDays = $('[name="contractDays"]').val();

			if (!cStart && !cEnd && !cDays) {
				alert('【开工日期、竣工日期】与【工期天数】必须选择一类进行填写！');
				return false;
			} else if (!cDays) {
				if (!cStart || !cEnd) {
					alert('开工日期与竣工日期必须同时填写！');
					return false;
				}
			} else {
				if (cStart || cEnd) {
					alert('【开工日期、竣工日期】与【工期天数】只能选择一类进行填写！');
					return false;
				}
			}

			$.suredy.showProcessDialog({
				keyboard : false,
				text : '<div class="text-danger"><i class="icon-spinner icon-spin"></i>&nbsp;数据提交中，请稍候……</div>'
			});

			// 修复[买标书费用]、[投标保证金]的资金去向
			$('.money-source').val($('input[name="otherCompany"]').val());

			form.ajaxSubmit({
				dataType : "json",
				success : function(data, textStatus, jqXHR) {
					if (!data || !data.success) {
						alert(data.msg || '信息修改失败!');
						$.suredy.closeProcessDialog();
						return false;
					}

					// notify config
					if ($.notifyDefaults) {
						$.notifyDefaults({
							allow_dismiss : false,
							placement : {
								align : 'center'
							},
							delay : 3000,
							mouse_over : 'pause',
							animate : {
								enter : 'animated flipInX',
								exit : 'animated flipOutX'
							}
						});
					}

					$.notify({
						title : '<span class="text-danger">提示！</span>',
						message : '信息修改成功！'
					});

					$.suredy.closeProcessDialog();

					window.opener.refresh();
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert('信息修改失败!\n' + errorThrown);
					$.suredy.closeProcessDialog();
					return false;
				}
			});
		});

		// 重置表单
		$('a.reset-form-info').on('click', function() {
			var form = $('form.form-create-contract');

			if (form.length > 0) {
				form[0].reset();
			}
		});
	});
</script>
</@t.foot>
